<template>
  <div>
    <el-radio-group v-model="queryParams.status" size="large" @change="getList()">
      <el-radio-button label="未接诊" value="0" />
      <el-radio-button label="已接诊" value="1" />
    </el-radio-group>
  </div>
  <div class="mb-2 flex items-center text-sm">
    <el-radio-group v-model="doctorStatus" class="ml-4" @change="updateDoctorStatus()">
      <el-radio value="0" size="large">关闭诊断</el-radio>
      <el-radio value="1" size="large">开启诊断</el-radio>
    </el-radio-group>
  </div>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="患者名称" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入患者名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="patientsList">
      <el-table-column label="序号" align="center">
        <template #default="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="日期" align="center" prop="dateOfAdmission" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.dateOfAdmission, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="金额" align="center" prop="consultationFee" />
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="消息" align="center" prop="message" />
      <el-table-column label="年龄" align="center" prop="patientAge" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="selected(scope.row)" v-if="scope.$index === 0 && queryParams.status===0">接诊</el-button>
          <el-button link type="primary" icon="Delete" @click="view(scope.row)">健康档案</el-button>
<!--          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['doctor:patients:edit']">修改</el-button>-->
<!--          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['doctor:patients:remove']">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="Patients">
import {
  listPatients,
  getPatients,
  delPatients,
  addPatients,
  updatePatients,
  updateStatus,
  getPatientsUserId
} from "@/api/doctor/patients";
import {parseTime} from "../../../utils/ruoyi.js";
import {useRoute, useRouter} from "vue-router";
import {receiveUpd} from "../../../api/doctor/patients.js";
const { proxy } = getCurrentInstance();

const doctorStatus=ref(0)
const patientsList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const route = useRoute();
const router = useRouter();
const patientId=ref(0)
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    id:null,
    dateOfAdmission: null,
    patientId: null,
    message: null,
    doctorId: null,
    status: 0,
    consultationFee:null,
    patientName:null,
    patientAge:null,
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询接诊列表 */
function getList() {
  loading.value = true;
  listPatients(data.queryParams).then(response => {
    patientsList.value = response.data.rows;
    total.value = response.data.total;
    loading.value = false;
  });
}
//修改医生状态
function updateDoctorStatus(){
  console.log(doctorStatus.value)
  updateStatus(doctorStatus.value).then(res =>{
  })
}
//接诊
function selected(data){
  getPatientsUserId(data.patientId).then(res=>{
    receiveUpd(data.id).then(res =>{
      alert("接诊成功");
    })
    patientId.value=res.data
    router.push({path:"/dialogue/index",query:{id:data.id,patientId:patientId.value}})
  })
}
//健康报告
function view(){

}
// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    dateOfAdmission: null,
    patientId: null,
    message: null,
    doctorId: null,
    status: null
  };
  proxy.resetForm("patientsRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}




getList();
</script>
